//
//  RegisterPasswordViewController.m
//  Youhuiju
//
//  Created by liuovyue on 16/9/8.
//  Copyright © 2016年 yutenys. All rights reserved.
//

#import "RegisterPasswordViewController.h"
#import "YHJMyCenterViewController.h"


@interface RegisterPasswordViewController ()

@property (strong, nonatomic) IBOutlet UIButton *buttonSure;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *buttonSureWidth;

@property (strong, nonatomic) IBOutlet UILabel *labelOne;




@property (nonatomic, strong)UILabel *labelTitle;
@property (nonatomic, strong)UIButton *buttonReturn;
@property (nonatomic, strong)UIView *viewBar;

@property (nonatomic, strong)UIView *viewBack;

@property (strong, nonatomic) IBOutlet UITextField *textFieldNewPassword;

@property (strong, nonatomic) IBOutlet UITextField *textFieldSurePassword;

@property (strong, nonatomic) IBOutlet UITextField *textFieldTelephone;



@end

@implementation RegisterPasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.buttonSureWidth.constant = 341*FitW;
    self.buttonSure.backgroundColor = [UIColor colorWithHexString:@"#fd487f"];
    
    self.labelOne.font = [UIFont systemFontOfSize:12*FitW];
    
    
    
    self.labelOne.textColor = [UIColor colorWithHexString:@"#fd487f"];
    [self createNavigationBar];
    self.labelOne.alpha = 0;
}


- (void)createNavigationBar{
    
    self.viewBar = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 64)];
    self.viewBar.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.viewBar];
    
    
    
    self.labelTitle = [[UILabel alloc]init];
    self.labelTitle.text = @"创建账户";
    self.labelTitle.textAlignment = NSTextAlignmentCenter;
    self.labelTitle.textColor = [UIColor blackColor];
    self.labelTitle.font = [UIFont systemFontOfSize:18*FitW];
    [self.viewBar addSubview:self.labelTitle];
    
    [_labelTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        
        //make.top.equalTo(self.viewBar.mas_top);
        make.left.equalTo(self.viewBar.mas_left).offset(100*FitW);
        make.right.equalTo(self.viewBar.mas_right).offset(-100*FitW);
        make.bottom.equalTo(self.viewBar.mas_bottom).offset(-14*FitH);
        
        
        
    }];
    //返回按钮
    self.buttonReturn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.buttonReturn setImage:[UIImage imageNamed:@"zfanhuijian"] forState:UIControlStateNormal];
    [self.buttonReturn addTarget:self action:@selector(tuihuiAcion:) forControlEvents:UIControlEventTouchUpInside];
    [self.viewBar addSubview:self.buttonReturn];
    
    [_buttonReturn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.viewBar.mas_left).offset(17*FitW);
        make.width.mas_equalTo(22*FitW);
        make.height.mas_equalTo(22*FitH);
        make.bottom.equalTo(self.viewBar.mas_bottom).offset(-13*FitH);
        
        
        
    }];
    
    
}
- (void)tuihuiAcion:(UIButton *)button {
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)sureAction:(id)sender {
    
    NSError *error = NULL;
    NSRegularExpression *regex = [NSRegularExpression
                                  regularExpressionWithPattern:@"([^A-Za-z0-9\u4e00-\u9fff])"
                                  options:0
                                  error:&error];
    
    NSString *resString = [regex stringByReplacingMatchesInString:self.textFieldNewPassword.text options:0 range:NSMakeRange(0, self.textFieldNewPassword.text.length) withTemplate:@""];
    if ([self.textFieldNewPassword.text isEqualToString:resString]&&self.textFieldNewPassword.text.length < 21&&self.textFieldNewPassword.text.length >5) {
        
        if (self.textFieldSurePassword.text == self.textFieldNewPassword.text) {
            self.tabBarController.tabBar.hidden = NO;
            YHJMyCenterViewController *logein = [[YHJMyCenterViewController alloc]init];
            [self.navigationController pushViewController:logein animated:YES];
        }
        
        
        
    }else {
        
        
        
        self.labelOne.alpha = 1;
        
        
    }
    
    
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
